package com.loong.musicdemo.ui.mine.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.loong.musicdemo.R;
import com.loong.musicdemo.model.Song;

import java.util.List;

public class SongAdapter extends RecyclerView.Adapter<SongAdapter.ViewHolder>{
    List<Song> recentSongs;

    public SongAdapter(List<Song> recentSongs) {
        this.recentSongs = recentSongs;
    }

    @NonNull
    @Override
    public SongAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recent_songs_item,parent,false);
        SongAdapter.ViewHolder holder = new SongAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull SongAdapter.ViewHolder holder, int position) {
        Song song = recentSongs.get(position);
        holder.song_name.setText(song.getName());
        holder.song_info.setText(song.getSingerName()+"-"+song.getAlbumName());
    }

    @Override
    public int getItemCount() {
        return recentSongs.size();
    }
    class ViewHolder extends RecyclerView.ViewHolder {
        TextView song_name,song_info;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            song_name = itemView.findViewById(R.id.recent_song_name);
            song_info = itemView.findViewById(R.id.recent_song_info);
        }
    }
}
